﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace OnlineLearningSystem.Repository.Migrations
{
    public partial class InitialCreate16 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Users_Batchs_BatchID",
                table: "Users");

            migrationBuilder.DropIndex(
                name: "IX_Users_BatchID",
                table: "Users");

            migrationBuilder.DropColumn(
                name: "BatchID",
                table: "Users");

            migrationBuilder.AddColumn<int>(
                name: "type",
                table: "Topics",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "BatchUser",
                columns: table => new
                {
                    UsersID = table.Column<int>(type: "int", nullable: false),
                    batchsID = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BatchUser", x => new { x.UsersID, x.batchsID });
                    table.ForeignKey(
                        name: "FK_BatchUser_Batchs_batchsID",
                        column: x => x.batchsID,
                        principalTable: "Batchs",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_BatchUser_Users_UsersID",
                        column: x => x.UsersID,
                        principalTable: "Users",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BatchUser_batchsID",
                table: "BatchUser",
                column: "batchsID");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BatchUser");

            migrationBuilder.DropColumn(
                name: "type",
                table: "Topics");

            migrationBuilder.AddColumn<int>(
                name: "BatchID",
                table: "Users",
                type: "int",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_Users_BatchID",
                table: "Users",
                column: "BatchID");

            migrationBuilder.AddForeignKey(
                name: "FK_Users_Batchs_BatchID",
                table: "Users",
                column: "BatchID",
                principalTable: "Batchs",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
